(function(e,t,n,r,i,a){"use strict";function s(){var e=babelHelpers.taggedTemplateLiteral(['<div class="main-user-field-enum-row-list-target"></div>']);s=function t(){return e};return e}function l(){var e=babelHelpers.taggedTemplateLiteral(['<div class="main-user-field-enum-row-drag-target"></div>']);l=function t(){return e};return e}function o(){var e=babelHelpers.taggedTemplateLiteral(["<option ",' value="','" data-id="','">',"</option>"]);o=function t(){return e};return e}function u(){var e=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t<div class="main-user-field-enum-row" data-role="main-user-field-enum-row">\n\t\t\t\t\t\t<div class="main-user-field-enum-row-inner ui-ctl ui-ctl-textbox ui-ctl-w100 ui-ctl-row">\n\t\t\t\t\t\t\t<span class="main-user-field-enum-row-draggable" style=""></span>\n\t\t\t\t\t\t\t','\n\t\t\t\t\t\t\t<div class="main-user-field-enum-delete" onclick="','"></div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>']);u=function t(){return e};return e}function d(){var e=babelHelpers.taggedTemplateLiteral(['<input class="ui-ctl-element" type="text" name="ENUM[][VALUE]" value=""\n\t\t\t\t\t\t\t\t data-role="main-user-field-enum-value"\n\t\t\t\t\t\t\t\t onchange="','">']);d=function t(){return e};return e}function h(e,t){var n;if(typeof Symbol==="undefined"||e[Symbol.iterator]==null){if(Array.isArray(e)||(n=c(e))||t&&e&&typeof e.length==="number"){if(n)e=n;var r=0;var i=function e(){};return{s:i,n:function t(){if(r>=e.length)return{done:true};return{done:false,value:e[r++]}},e:function e(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=true,s=false,l;return{s:function t(){n=e[Symbol.iterator]()},n:function e(){var t=n.next();a=t.done;return t},e:function e(t){s=true;l=t},f:function e(){try{if(!a&&n.return!=null)n.return()}finally{if(s)throw l}}}}function c(e,t){if(!e)return;if(typeof e==="string")return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.constructor.name;if(n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}function f(e,t){if(t==null||t>e.length)t=e.length;for(var n=0,r=new Array(t);n<t;n++){r[n]=e[n]}return r}function g(e,t,n){if(e!==t){throw new TypeError("Private static access of wrong provenance")}if(n.get){return n.get.call(e)}return n.value}var m=t.Reflection.namespace("BX.Main.UserField");var v=function(){function e(n){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"id",0);babelHelpers.defineProperty(this,"inputs",new Map);babelHelpers.defineProperty(this,"tabs",new Map);babelHelpers.defineProperty(this,"container",null);babelHelpers.defineProperty(this,"settingsContainer",null);babelHelpers.defineProperty(this,"settingsTable",null);babelHelpers.defineProperty(this,"errorsContainer",null);babelHelpers.defineProperty(this,"saveButton",null);babelHelpers.defineProperty(this,"cancelButton",null);babelHelpers.defineProperty(this,"deleteButton",null);this.tabs=new Map;this.inputs=new Map;var r=document.getElementById("ui-button-panel-save");if(r){this.saveButton=a.ButtonManager.createFromNode(r)}var i=document.getElementById("ui-button-panel-cancel");if(i){this.cancelButton=a.ButtonManager.createFromNode(i)}var s=document.getElementById("ui-button-panel-remove");if(s){this.deleteButton=a.ButtonManager.createFromNode(s)}if(t.Type.isPlainObject(n)){this.id=t.Text.toInteger(n.id);if(t.Type.isDomNode(n.container)){this.container=n.container}if(t.Type.isDomNode(n.errorsContainer)){this.errorsContainer=n.errorsContainer}this.moduleId=n.moduleId}this.bindEvents();this.fillTabs();g(this.constructor,e,p).set(this.id,this);this.adjustVisibility();this.syncEnumDefaultSelector()}babelHelpers.createClass(e,[{key:"getBooleanInputNames",value:function e(){return["multiple","mandatory","showFilter","isSearchable"]}},{key:"getSettingsContainer",value:function e(){if(this.container&&!this.settingsContainer){this.settingsContainer=this.container.querySelector('[data-role="main-user-field-settings-container"]')}return this.settingsContainer}},{key:"getSettingsTable",value:function e(){if(!this.settingsTable){var t=this.getSettingsContainer();if(t){this.settingsTable=t.querySelector('[data-role="main-user-field-settings-table"]')}}return this.settingsTable}},{key:"fillTabs",value:function e(){var t=this;var n=["common","labels","additional","list"];if(this.container){n.forEach((function(e){var n=t.container.querySelector('[data-tab="'+e+'"]');if(n){t.tabs.set(e,n)}}))}}},{key:"showTab",value:function e(t){var n=this;Array.from(this.tabs.keys()).forEach((function(e){if(e===t){n.tabs.get(e).classList.add("main-user-field-edit-tab-current");if(t==="list"){n.syncEnumDefaultSelector()}}else{n.tabs.get(e).classList.remove("main-user-field-edit-tab-current")}}))}},{key:"getInput",value:function e(t){if(this.container&&!this.inputs.has(t)){var n=this.container.querySelector('[data-role="main-user-field-'+t+'"]');if(n){this.inputs.set(t,n)}}return this.inputs.get(t)}},{key:"getInputValue",value:function e(t){if(t==="userTypeId"){return this.getSelectedUserTypeId()}var n=this.getInput(t);if(n){if(this.getBooleanInputNames().includes(t)){return n.checked?"Y":"N"}return n.value}return""}},{key:"bindEvents",value:function e(){var n=this;var r=this.getInput("userTypeId");if(r){t.Event.bind(r,"change",this.handleUserTypeChange.bind(this))}var i=this.getInput("editFormLabel");if(i&&i.parentElement&&i.parentElement.parentElement){var a=i.parentElement.parentElement.dataset["language"];var s=this.getInput("editFormLabel-"+a);if(s){t.Event.bind(i,"change",(function(){n.syncLabelInputs(i,s)}));t.Event.bind(s,"change",(function(){n.syncLabelInputs(s,i)}))}}var l=this.container.querySelector('[data-role="main-user-field-enum-add"]');if(l){t.Event.bind(l,"click",this.addEnumRow.bind(this))}var o=Array.from(this.container.querySelectorAll('[data-role="main-user-field-enum-delete"]'));o.forEach((function(e){t.Event.bind(e,"click",n.deleteEnumRow.bind(n))}));var u=Array.from(this.container.querySelectorAll('[data-role="main-user-field-enum-row"]'));u.forEach((function(e){var r=e.querySelector('[data-role="main-user-field-enum-value"]');if(r){t.Event.bind(r,"change",n.syncEnumDefaultSelector.bind(n))}}));t.Event.bind(this.saveButton.getContainer(),"click",(function(e){e.preventDefault();n.save()}),{passive:false});if(this.deleteButton){t.Event.bind(this.deleteButton.getContainer(),"click",(function(e){e.preventDefault();n.delete()}))}}},{key:"getSelectedUserTypeId",value:function e(){var t=this.getSelectedOption("userTypeId");if(t){return t.value}return null}},{key:"getSelectedOption",value:function e(t){var n=this.getInput(t);if(n){var r=Array.from(n.querySelectorAll("option"));var i=n.selectedIndex;return r[i]}return null}},{key:"getSelectedOptions",value:function e(t){var n=this.getInput(t);if(n&&n instanceof HTMLSelectElement){return n.selectedOptions}return null}},{key:"handleUserTypeChange",value:function e(){var n=this;if(this.isProgress){return}var r=this.getSettingsTable();if(!r){return}var i=this.getSelectedUserTypeId();if(!i){return}this.startProgress();t.ajax.runComponentAction("bitrix:main.field.config.detail","getSettings",{data:{userTypeId:i},analyticsLabel:"mainUserFieldConfigGetSettings",mode:"class"}).then((function(e){n.stopProgress();var i="";if(e.data.html&&e.data.html.length>0){i=e.data.html}t.Runtime.html(r,i).then((function(){n.adjustVisibility()}))})).catch((function(e){n.stopProgress();n.showErrors(e.errors)}))}},{key:"getLoader",value:function e(){if(!this.loader){this.loader=new n.Loader({size:150})}return this.loader}},{key:"startProgress",value:function e(){this.isProgress=true;if(!this.getLoader().isShown()){this.getLoader().show(this.container)}this.hideErrors()}},{key:"stopProgress",value:function e(){var n=this;this.isProgress=false;this.getLoader().hide();setTimeout((function(){n.saveButton.setWaiting(false);t.Dom.removeClass(n.saveButton.getContainer(),"ui-btn-wait");if(n.deleteButton){n.deleteButton.setWaiting(false);t.Dom.removeClass(n.deleteButton.getContainer(),"ui-btn-wait")}}),200)}},{key:"showErrors",value:function e(n){var r="";n.forEach((function(e){r+=e}));if(t.Type.isDomNode(this.errorsContainer)){this.errorsContainer.innerText=r;this.errorsContainer.parentElement.style.display="block"}else{console.error(r)}}},{key:"hideErrors",value:function e(){if(t.Type.isDomNode(this.errorsContainer)){this.errorsContainer.innerText="";this.errorsContainer.parentElement.style.display="none"}}},{key:"getSettings",value:function e(){var t={};var n=this.container.querySelector('[data-role="main-user-field-settings"]');if(n){var r=new FormData(n);var i=h(r.entries()),a;try{for(i.s();!(a=i.n()).done;){var s=a.value;var l=s[0].substr(9,s[0].length-10);t[l]=s[1]}}catch(e){i.e(e)}finally{i.f()}}return t}},{key:"prepareFieldData",value:function e(){var n=this;if(!this.container){return{}}var r={};var i=Array.from(this.container.querySelectorAll('[data-role="main-user-field-label-container"]'));i.forEach((function(e){var t=e.dataset["language"];r[t]=n.getInputValue("editFormLabel-"+t)}));var a=[];var s=this.getInputValue("userTypeId");if(s==="enumeration"){this.syncEnumDefaultSelector();var l=this.getSelectedEnumDefaultAttributes();var o=100;var u=0;var d=Array.from(this.container.querySelectorAll('[data-role="main-user-field-enum-row"]'));d.forEach((function(e){var n=e.querySelector('[data-role="main-user-field-enum-value"]');if(!n){return}var r=t.Text.toInteger(e.dataset["id"]);var i=n.value;var s="N";if(r>0&&l.id.includes(r)||l.value.includes(i)){s="Y"}u+=o;a.push({value:n.value,def:s,sort:u,id:r})}))}var h=t.Text.toInteger(this.getInputValue("id"));var c=this.getInputValue("fieldName");if(h<=0){c=this.getInputValue("fieldPrefix")+c}return{id:h,editFormLabel:r,entityId:this.getInputValue("entityId"),fieldName:c,sort:this.getInputValue("sort"),multiple:this.getInputValue("multiple"),mandatory:this.getInputValue("mandatory"),showFilter:this.getInputValue("showFilter"),isSearchable:this.getInputValue("isSearchable"),userTypeId:s,settings:this.getSettings(),enum:a}}},{key:"save",value:function e(){var t=this;if(this.isProgress){return}if(!this.moduleId){return}this.startProgress();var n=this.prepareFieldData();var r=null;var a=this.getInput("editFormLabel");if(a&&a.parentElement&&a.parentElement.parentElement){r=a.parentElement.parentElement.dataset["language"]}var s=new i.UserField(n,{languageId:r,moduleId:this.moduleId});s.save().then((function(){t.afterSave(s);t.stopProgress()})).catch((function(e){t.showErrors(e);t.stopProgress()}))}},{key:"delete",value:function e(){var n=this;if(this.isProgress){return}if(!this.moduleId){return}var a=t.Text.toInteger(this.getInputValue("id"));if(a<=0){return}r.MessageBox.confirm(t.Loc.getMessage("MAIN_FIELD_CONFIG_DELETE_CONFIRM"),(function(){return new Promise((function(e){var a=new i.UserField(n.prepareFieldData(),{moduleId:n.moduleId});n.startProgress();a.delete().then((function(){n.stopProgress();var i=n.getSlider();if(i){n.addDataToSlider("userFieldData",a.serialize());i.close()}else{r.MessageBox.alert(t.Loc.getMessage("MAIN_FIELD_CONFIG_DELETE_SUCCESS"))}e()})).catch((function(t){n.stopProgress();n.showErrors(t);e()}))}))}),null,(function(e){n.stopProgress();e.close()}))}},{key:"adjustVisibility",value:function e(){var t=this.getSettingsTable();var n=document.querySelector('[data-role="tab-additional"]');var r=document.querySelector('[data-role="tab-list"]');if(!t||!n||!r){return}if(t.childElementCount<=0){n.style.display="none"}else{n.style.display="block"}var i=this.getSelectedUserTypeId();if(i==="enumeration"){r.style.display="flex"}else{r.style.display="none"}if(i==="boolean"){this.changeInputVisibility("multiple","none");this.changeInputVisibility("mandatory","none")}else{this.changeInputVisibility("multiple","block");this.changeInputVisibility("mandatory","block")}}},{key:"changeInputVisibility",value:function e(t,n){var r=this.getInput(t);if(r&&r.parentElement&&r.parentElement.parentElement){r.parentElement.parentElement.style.display=n}}},{key:"afterSave",value:function e(n){this.addDataToSlider("userFieldData",n.serialize());var r=this.getSlider();if(r){r.close()}else{var i=t.Text.toInteger(this.getInputValue("id"));if(i<=0){if(!!n.getDetailUrl()){location.href=n.getDetailUrl();return}this.getInput("id").value=n.getId();var a=this.getInput("fieldPrefix");if(a&&a.parentElement&&a.parentElement.parentElement){a.parentElement.parentElement.classList.remove("main-user-field-name-with-prefix");t.Dom.remove(a.parentElement)}this.getInput("fieldName").value=n.getName();this.getInput("fieldName").disabled=true;this.getInput("fieldName").parentElement.classList.remove("ui-ctl-inline")}}}},{key:"getSlider",value:function e(){if(t.Reflection.getClass("BX.SidePanel")){return BX.SidePanel.Instance.getSliderByWindow(window)}return null}},{key:"addDataToSlider",value:function e(n,r){if(t.Type.isString(n)){var i=this.getSlider();if(i){i.getData().set(n,r);BX.SidePanel.Instance.postMessage(i,"userfield-list-update")}}}},{key:"syncLabelInputs",value:function e(t,n){var r=t.closest(".main-user-field-edit-tab");if(r&&r.classList.contains("main-user-field-edit-tab-current")){n.value=t.value}}},{key:"addEnumRow",value:function e(){var n=this.container.querySelector('[data-role="main-user-field-enum-add"]');if(n){var r=t.Tag.render(d(),this.syncEnumDefaultSelector.bind(this));var i=t.Tag.render(u(),r,this.deleteEnumRow.bind(this));t.Dom.append(i,document.querySelector(".main-user-field-enum-row-list"));r.focus();var a=new y;a.init(i)}}},{key:"deleteEnumRow",value:function e(n){var r=n.target;t.Dom.remove(r.parentElement);this.syncEnumDefaultSelector()}},{key:"getSelectedEnumDefaultAttributes",value:function e(){var n={id:[],value:[]};var r=this.getSelectedOptions("enumDefault");if(r){Array.from(r).forEach((function(e){if(e.dataset["id"]&&e.dataset["id"]>0){n["id"].push(t.Text.toInteger(e.dataset["id"]))}else{n["value"].push(e.value)}}))}return n}},{key:"syncEnumDefaultSelector",value:function e(){var n=this.getInputValue("userTypeId");if(n==="enumeration"){var r=this.getInput("enumDefault");if(!r){return}var i=this.getInputValue("multiple");if(i==="Y"){r.multiple=true;r.size=3;r.parentElement.classList.add("ui-ctl-multiple-select");r.parentElement.classList.remove("ui-ctl-after-icon");r.parentElement.classList.remove("ui-ctl-dropdown")}else{r.multiple=false;r.parentElement.classList.remove("ui-ctl-multiple-select");r.parentElement.classList.add("ui-ctl-after-icon");r.parentElement.classList.add("ui-ctl-dropdown")}var a=this.getSelectedEnumDefaultAttributes();var s=Array.from(r.querySelectorAll("option"));s.forEach((function(e){if(e.value!=="empty"){t.Dom.remove(e)}}));var l=Array.from(this.container.querySelectorAll('[data-role="main-user-field-enum-row"]'));l.forEach((function(e){var n=t.Text.toInteger(e.dataset["id"]);var i=e.querySelector('[data-role="main-user-field-enum-value"]');if(!i){return}var s=i.value;var l=n>0&&a.id.includes(n)||a.value.includes(s);if(s.length>0){r.appendChild(t.Tag.render(o(),l?'selected="selected"':"",t.Text.encode(s),n,t.Text.encode(s)))}}))}}}],[{key:"handleLeftMenuClick",value:function t(n,r){if(g(e,e,p)){var i=g(e,e,p).get(n);if(i){i.showTab(r)}}}}]);return e}();var p={writable:true,value:new Map};var y=function(){function e(){babelHelpers.classCallCheck(this,e);this.itemContainer=null;this.draggableItemContainer=null;this.dragElement=null}babelHelpers.createClass(e,[{key:"init",value:function e(t){this.itemContainer=t;var n=this.itemContainer.querySelector(".main-user-field-enum-row-draggable");if(jsDD){n.onbxdragstart=this.onDragStart.bind(this);n.onbxdrag=this.onDrag.bind(this);n.onbxdragstop=this.onDragStop.bind(this);jsDD.registerObject(n);this.itemContainer.onbxdestdraghover=this.onDragEnter.bind(this);this.itemContainer.onbxdestdraghout=this.onDragLeave.bind(this);this.itemContainer.onbxdestdragfinish=this.onDragDrop.bind(this);jsDD.registerDest(this.itemContainer,30)}}},{key:"onDragStart",value:function e(){t.Dom.addClass(this.itemContainer,"main-user-field-enum-row-disabled");if(!this.dragElement){this.dragElement=this.itemContainer.cloneNode(true);this.dragElement.style.position="absolute";this.dragElement.style.width=this.itemContainer.offsetWidth+"px";this.dragElement.className="main-user-field-enum-row-drag";t.Dom.append(this.dragElement,document.body)}}},{key:"onDrag",value:function e(t,n){if(this.dragElement){this.dragElement.style.left=t+"px";this.dragElement.style.top=n+"px"}}},{key:"onDragStop",value:function e(){t.Dom.removeClass(this.itemContainer,"main-user-field-enum-row-disabled");t.Dom.remove(this.dragElement);this.dragElement=null}},{key:"onDragEnter",value:function e(t){this.draggableBtnContainer=t.closest(".main-user-field-enum-row");if(this.draggableBtnContainer!==this.itemContainer){this.showDragTarget()}}},{key:"onDragLeave",value:function e(){this.hideDragTarget()}},{key:"onDragDrop",value:function e(){if(this.draggableBtnContainer!==this.itemContainer){this.hideDragTarget();t.Dom.remove(this.draggableBtnContainer);t.Dom.insertBefore(this.draggableBtnContainer,this.itemContainer)}}},{key:"showDragTarget",value:function e(){t.Dom.addClass(this.itemContainer,"main-user-field-enum-row-target-shown");this.getDragTarget().style.height=this.itemContainer.offsetHeight+"px"}},{key:"hideDragTarget",value:function e(){t.Dom.removeClass(this.itemContainer,"main-user-field-enum-row-target-shown");this.getDragTarget().style.height=0}},{key:"getDragTarget",value:function e(){if(!this.dragTarget){this.dragTarget=t.Tag.render(l());t.Dom.prepend(this.dragTarget,this.itemContainer)}return this.dragTarget}}]);return e}();var b=function(){function e(){babelHelpers.classCallCheck(this,e);this.container=document.querySelector(".main-user-field-enum-row-list");this.height=null}babelHelpers.createClass(e,[{key:"init",value:function e(){this.container.onbxdestdraghover=BX.delegate(this.onDragEnter,this);this.container.onbxdestdraghout=BX.delegate(this.onDragLeave,this);this.container.onbxdestdragfinish=BX.delegate(this.onDragDrop,this);jsDD.registerDest(this.container,40)}},{key:"onDragEnter",value:function e(t){this.draggableBtnContainer=t.closest(".main-user-field-enum-row");this.height=this.draggableBtnContainer.offsetHeight;this.showDragTarget()}},{key:"onDragLeave",value:function e(){this.hideDragTarget()}},{key:"onDragDrop",value:function e(){this.hideDragTarget();t.Dom.remove(this.draggableBtnContainer);t.Dom.insertBefore(this.draggableBtnContainer,this.dragTarget)}},{key:"showDragTarget",value:function e(){t.Dom.addClass(this.container,"main-user-field-enum-row-list-target-shown");this.getDragTarget().style.height=this.height+"px"}},{key:"hideDragTarget",value:function e(){t.Dom.removeClass(this.container,"main-user-field-enum-row-list-target-shown");this.getDragTarget().style.height=0}},{key:"getDragTarget",value:function e(){if(!this.dragTarget){this.dragTarget=t.Tag.render(s());t.Dom.append(this.dragTarget,this.container)}return this.dragTarget}}]);return e}();m.Config=v;m.DragDropItem=y;m.DragDropBtnContainer=b})(this.window=this.window||{},BX,BX,BX.UI.Dialogs,BX.UI.UserField,BX.UI);
//# sourceMappingURL=script.map.js